<?php

namespace App\Http\Controllers\Api\V1;

use App\Models\Product;
use App\Models\Comment;
use App\Services\Cache\CommentCache;
use App\Services\MakeProductComment\MakeProductComment;
use App\Http\Controllers\Api\V1\Resources\CommentResource;
use App\Services\MakeProductComment\MakeProductCommentRequest;

class CommentsController extends Controller
{

	public function index()
	{
		$product = Product::find(request('pid'));
		$comments = app(CommentCache::class)->comments($product);
		return CommentResource::collection($comments);
	}

    public function product(MakeProductCommentRequest $request)
    {
    	$comment = app(MakeProductComment::class, [
    		'order' => $request->getOrder(),
		    'data' => $request->data
	    ])->make();

	    return new CommentResource($comment);
    }
}
